package day10;

import java.io.*;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Tihuan3 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("输入一个文件名");
        String filename = in.next();
        String filename1 = filename.replace(".", "1.");
        System.out.println(filename1);
        File file = new File(filename);
        if (file.exists()) {
            InputStream a = null;
            OutputStream b = null;
            try {
                a = new FileInputStream(filename);
                b = new FileOutputStream(filename1);
                int c;
                while ((c = a.read()) != -1) {
                    b.write((~(byte) c));
                }
                a.close();
                b.close();
                boolean f=file.delete();
                System.out.println("删除的结果："+f);
                File d = new File(filename1);
                d.renameTo(new File(filename));
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
//                if (a != null) {
//                    try {
//                        a.close();
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                }
//                if (b != null) {
//                    try {
//                        b.close();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                }
            }
        } else {
            System.out.println("文件不存在");
        }

    }
}